package com.hz.erp.utils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * @author 柯鑫
 * @ClassName com.hz.erp.utils.MathUtils
 * @description Math工具类
 * @create 2020年06月09日 9:47
 */
public class MathUtils {

    /**
     * BigDecimal a > b
     * @param a
     * @param b
     * @return
     */
    public static boolean compareToBigDecimalGreater(BigDecimal a, BigDecimal b){
        if(a.compareTo(b) == 1)
            return true;

        return false;
    }

    /**
     * BigDecimal a = b
     * @param a
     * @param b
     * @return
     */
    public static boolean compareToBigDecimalSame(BigDecimal a, BigDecimal b){
        if(a.compareTo(b) == 0)
            return true;

        return false;
    }

    /**
     * BigDecimal a < b
     * @param a
     * @param b
     * @return
     */
    public static boolean compareToBigDecimalLess(BigDecimal a, BigDecimal b){
        if(a.compareTo(b) == -1)
            return true;

        return false;
    }

    /**
     * 判断BigDecimal是否为null
     * @param bigDecimal
     * @return
     */
    public static boolean compareToDecimalNull(BigDecimal bigDecimal){
        if(null == bigDecimal || bigDecimal.compareTo(BigDecimal.ZERO) == 0){
            return true;
        }
        return false;
    }

    /**
     * 判断Long类型是否为空或null
     * @param param
     * @return
     */
    public static boolean isNullOrZero(Long param){
        if(null == param || param == 0){
            return true;
        }
        return false;
    }


    /**
     * 16进制转化为10进制
     * @param contentStr
     * @return
     */
    public static int covert(String contentStr){
        int number=0;
        String content = contentStr.toUpperCase();
        String [] HighLetter = {"A","B","C","D","E","F"};
        Map<String,Integer> map = new HashMap<>();
        for(int i = 0;i <= 9;i++){
            map.put(i+"",i);
        }
        for(int j= 10;j<HighLetter.length+10;j++){
            map.put(HighLetter[j-10],j);
        }
        String[]str = new String[content.length()];
        for(int i = 0; i < str.length; i++){
            str[i] = content.substring(i,i+1);
        }
        for(int i = 0; i < str.length; i++){
            number += map.get(str[i])*Math.pow(16,str.length-1-i);
        }
        return number;
    }

    /**
     * int 类型转化为 BigDecimal
     * @param num
     * @return
     */
    public static BigDecimal temConvert(int num){
        double newNum = num * 0.1;
        BigDecimal bigDecimal = BigDecimal.valueOf(newNum);
        return bigDecimal;
    }

    /**
     * 校验手机号码
     * @param in
     * @return
     */
    public static boolean validateMobilePhone(String in){
        Pattern pattern = Pattern.compile("^[1]\\d{10}$");
        return pattern.matcher(in).matches();
    }

}
